package com.ruoyi.web.controller.cat;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cat.domain.CatComplaint;
import com.ruoyi.cat.domain.VO.CatComplaintVO;
import com.ruoyi.cat.service.ICatComplaintService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投诉意见Controller
 * 
 * @author ruoyi
 * @date 2025-01-04
 */

@Api(tags = "管理端-投诉相关接口")
@RestController
@RequestMapping("/system/complaint")
public class CatComplaintController extends BaseController
{
    @Autowired
    private ICatComplaintService catComplaintService;

    /**
     * 查询投诉意见列表
     */
    @ApiOperation("管理端-获取投诉列表")
    @PreAuthorize("@ss.hasPermi('system:complaint:list')")
    @GetMapping("/list")
    public TableDataInfo list(CatComplaint catComplaint)
    {
        startPage();
        List<CatComplaint> list = catComplaintService.selectCatComplaintList(catComplaint);
        return getDataTable(list);
    }
    @ApiOperation("管理端-修改投诉状态")
    @PostMapping("/editCom")
    public AjaxResult editCom(@RequestBody CatComplaintVO catComplaint)
    {
        CatComplaint complaint = new CatComplaint();
        complaint.setState("1");
        complaint.setId(catComplaint.getId());
        return toAjax(catComplaintService.updateCatComplaint(complaint));
    }

    /**
     * 导出投诉意见列表
     */
    @PreAuthorize("@ss.hasPermi('system:complaint:export')")
    @Log(title = "投诉意见", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CatComplaint catComplaint)
    {
        List<CatComplaint> list = catComplaintService.selectCatComplaintList(catComplaint);
        ExcelUtil<CatComplaint> util = new ExcelUtil<CatComplaint>(CatComplaint.class);
        util.exportExcel(response, list, "投诉意见数据");
    }

    /**
     * 获取投诉意见详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:complaint:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(catComplaintService.selectCatComplaintById(id));
    }

    /**
     * 新增投诉意见
     */
    @PreAuthorize("@ss.hasPermi('system:complaint:add')")
    @Log(title = "投诉意见", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CatComplaint catComplaint)
    {
        return toAjax(catComplaintService.insertCatComplaint(catComplaint));
    }

    /**
     * 修改投诉意见
     */
    @PreAuthorize("@ss.hasPermi('system:complaint:edit')")
    @Log(title = "投诉意见", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CatComplaint catComplaint)
    {
        return toAjax(catComplaintService.updateCatComplaint(catComplaint));
    }

    /**
     * 删除投诉意见
     */
    @PreAuthorize("@ss.hasPermi('system:complaint:remove')")
    @Log(title = "投诉意见", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(catComplaintService.deleteCatComplaintByIds(ids));
    }
}
